<?php

$db		= new Kegiatan();
$table 	= "kegiatan";
$table2 = "kabkota";
$table3 = "sektoral";
$id  = "";
$order = "idkegiatan";
$kegiatan = $db->lihat($table,$table2,$table3,$order, $id);

$o .= '<a class="btn btn-primary" href="?page=addkegiatan"><i class="icon-plus"></i> Tambah Data</a><br><br>';

if ($kegiatan) {
	if (isset($_GET['success']) && ($_GET['success'] == "1")) {

		$o .= '<div class="alert alert-success">
				hapus data kegiatan berhasil
				</div>';
					
		} elseif (isset($_GET['success']) && ($_GET['success'] == "0")) {
				
			$o .= '<div class="alert alert-error">
					hapus data kegiatan gagal
				   </div>';
		}
	$o .= '<table class="table table-striped table-bordered table-condensed">
			<tr>
				<th><center>No</th>
				<th><center>Nama Kegiatan</th>
				<th><center>Kabupaten</th>
				<th><center>Sektoral</th>
				<th><center>Operator</th>
				<th colspan=4><center>Tindakan</th>
			</tr> ';
	
	$no = 1;
	
	foreach($kegiatan as $x) {
		
		$o .= '<tr>
					<td><center>'.$no.'</td>
					<td><center>'.$x['nama_kegiatan'].'</td>
					<td><center>'.$x['kabupaten'].'</td>
					<td><center>'.$x['sektoral'].'</td>
					<td><center>'.$x['username'].'</td>
					<td><center><a href="?page=detailkegiatan&id='.$x['idkegiatan'].'"><i class="icon-zoom-in"></i> Detail</a></td>
					<td><center><a href="?page=monitoring&id='.$x['idkegiatan'].'"><i class="icon-edit"></i> Monitoring</a></td>
					<td><center><a href="?page=editkegiatan&id='.$x['idkegiatan'].'"><i class="icon-wrench"></i> Ubah</a></td>
					<td><center><a href="?page=kegiatan&action=delete&id='.$x['idkegiatan'].'"><i class="icon-remove"></i> Hapus</a></td>
			  </tr>';
			  
		 
			  
		$no++;
		
	}

	$o .= '</table>';

} else {

	$o .= '<div class="alert alert-error">
		  <center>Data kosong</center>
		  </div>';
} 

echo $o;

if ($_GET['action'] == "delete") {

	$id = htmlentities(mysql_real_escape_string($_GET['id']));
	$hapuskegiatan = $db->hapus($table,$id);
	if ($hapuskegiatan) {
		?>
			<script language="javascript">
			document.location="?page=kegiatan&success=1";
			</script>
		<?php
		
	} else {
		?>
			<script language="javascript">
			document.location="?page=kegiatan&success=0";
			</script>
		<?php
	}
}
